<?php

namespace App\Http\Controllers\V1\Admin;


use App\Models\V1\District;
use Illuminate\Http\Request;

class DistrictController extends BaseController
{

    /**
     * 广告位列表
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $query = District::query();
        $pageSize = $request->input('pageSize', 100);
        $query->where('pid', $request->input('pid', 0));
        $data = $query->paginate($pageSize);
        return ajax_output(200, "成功", $data);
    }


    /**
     * 购买盒子广告位
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $model = new District();
        $model->create([
            'title' => $request->input('title', ""),
            'code' => $request->input('code', ""),
            'remark' => $request->input('remark', ""),
            'state' => $request->input('state', 1)
        ]);

        return ajax_output(200, "成功");
    }

    /**
     * 盒子广告位详情
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $vo = District::find($id);
        return ajax_output(200, "成功", $vo);
    }


    /**
     * 更新盒子广告位
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $vo = District::find($id);
        $vo->update([
            'title' => $request->input('title', ""),
            'code' => $request->input('code', ""),
            'remark' => $request->input('remark', ""),
            'state' => $request->input('state', 1)
        ]);
        return ajax_output(200, "成功");
    }

    /**
     * 删除广告位
     *
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $id = explode(',', $id);
        District::destroy($id);
        return ajax_output(200, "成功");
    }

    /**
     * 广告位列表
     *
     * @return \Illuminate\Http\Response
     */
    public function selectList(Request $request)
    {
        $area_model = new District();
        $data = $area_model->select("id as value", 'title as label')->get();

        return ajax_output(200, "成功", $data);
    }
}
